Grab highway shape geometry
# map it
mapview(bay_highways_shp)
Grab all our sensors, both in our study and across the Bay (filtered to San Mateo County). Highways are merged via union for upcoming analysis.
mapview(all_27_sensors) + mapview(smc_highways)
Add a .5 mile buffer to highways to qualitatively compare air quality for sensors near and far from highways. .5 miles chosen arbitrarily.
mapview(smc_sensors_near_highway) + mapview(smc_highways)
leaflet() %>%
addMapboxTiles(
style_id = "light-v9",
username = "mapbox"
) %>%
addPolylines(
data = smc_highways,
fillColor = "black",
fillOpacity = 1,
color = "black",
weight = 2
) %>%
addPolygons(
data = highway_buffer,
fillColor = "yellow",
fillOpacity = .2,
color = "yellow",
weight = .2
) %>%
addCircleMarkers(
data = smc_sensors %>% filter(near_highway == "YES", type == "original"),
fillColor = "green",
fillOpacity = 1,
color = "black",
opacity = 1,
radius = 6,
weight = .8,
group = "Original Sensor Near from Highway"
) %>%
addCircleMarkers(
data = smc_sensors %>% filter(near_highway == "NO", type == "original"),
fillColor = "red",
fillOpacity = .5,
color = "black",
opacity = 1,
radius = 6,
weight = .2,
group = "Original Sensor Away from Highway"
) %>%
addCircleMarkers(
data = all_27_sensors %>% filter(near_highway == "YES", type == "participant"),
fillColor = "purple",
fillOpacity = 1,
color = "black",
opacity = 1,
radius = 6,
weight = .8,
group = "Participant Sensor Near Highway"
) %>%
addCircleMarkers(
data = all_27_sensors %>% filter(near_highway == "NO", type == "participant"),
fillColor = "purple",
fillOpacity = 1,
color = "black",
opacity = 1,
radius = 6,
weight = .2,
group = "Participant Sensor Away Highway"
) %>%
addLayersControl(
overlayGroups = c("Original Sensor Away from Highway",
"Original Sensor Near from Highway",
"Participant Sensor Near Highway",
"Participant Sensor Away Highway"),
options = layersControlOptions(collapsed = FALSE)
)
# mapshot(m, file = paste0(path, "highway_analysis.png"))
The plot below shows little difference between AQi in sensors near the highway or further away.
AQI_near_highway_plot <-
ggplot(data = SMC_summary,
aes(x = near_highway,
y = average_AQI)) +
geom_col() +
scale_fill_brewer(palette = "YlOrRd")
AQI_near_highway_plot
Use st_nearest to determine the distance from each sensor to the nearest highway. Below is a map that shows one sensor connected to its nearest highway.
nearest_distance <-
st_nearest_points(smc_sensors_AQI[1,],smc_highways) %>%
st_sf()
# visualize
leaflet() %>%
addMapboxTiles(
style_id = "light-v9",
username = "mapbox"
) %>%
addPolylines(
data = smc_highways,
fillColor = "black",
fillOpacity = 1,
color = "black",
weight = 2
) %>%
addPolygons(
data = highway_buffer,
fillColor = "yellow",
fillOpacity = .2,
color = "yellow",
weight = .2
) %>%
addCircleMarkers(
data = smc_sensors_AQI %>% filter(near_highway == "YES"),
fillColor = "green",
fillOpacity = 1,
color = "black",
opacity = 1,
radius = 6,
weight = .8,
group = "Original Sensor Near from Highway"
) %>%
addCircleMarkers(
data = smc_sensors_AQI %>% filter(near_highway == "NO"),
fillColor = "red",
fillOpacity = .5,
color = "black",
opacity = 1,
radius = 6,
weight = .2,
group = "Original Sensor Away from Highway"
) %>%
addPolylines(
data = nearest_distance %>%
st_transform(4326),
color = "blue",
weight = .5
) %>%
addLayersControl(
overlayGroups = c("Original Sensor Away from Highway",
"Original Sensor Near from Highway"),
options = layersControlOptions(collapsed = FALSE)
)
# distance_to_hwy <-
# st_nearest_points(smc_sensors_AQI[3,ncol(smc_sensors_AQI)],smc_highways) %>%
# st_length() %>%
# as.numeric()
First, plotting AQI relative to distance from highway, then a linear regression summary showing that according to our model, distance from highway is a poor predictor of AQI.
hwy_AQI_distance <- ggplot(smc_sensors_AQI,
aes(`d_to_hwy (m)`,AQI)
) +
geom_point() +
geom_smooth()
hwy_AQI_distance
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
# linear regression formula
fit <- lm(AQI ~ `d_to_hwy (m)`, data = smc_sensors_AQI)
summary(fit)
##
## Call:
## lm(formula = AQI ~ `d_to_hwy (m)`, data = smc_sensors_AQI)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.345 -3.345 -1.240 3.643 71.679
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.536e+01 2.798e-01 54.895 <2e-16 ***
## `d_to_hwy (m)` -4.175e-05 6.983e-05 -0.598 0.55
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.119 on 1040 degrees of freedom
## Multiple R-squared: 0.0003435, Adjusted R-squared: -0.0006177
## F-statistic: 0.3574 on 1 and 1040 DF, p-value: 0.5501
For every meter increase in distance to highway, our model predicts a -4.175 decrease in AQI.